import { createRouter, createWebHistory } from "vue-router";
import Congraduate from "../view/Congraduate.vue";
import NotFound from "../view/NotFound.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),

  routes: [
    {
      path: "/",
      name: "congraduate",
      component: Congraduate,
      meta: {
        title: "庆祝",
      },
    },
    {
      path: "/notfound",
      name: "notfound",
      component: NotFound,
      meta: {
        title: "页面走丢了",
      },
    },
    {
      // 其他不匹配路由，转发到 404 页面 - 应该放在路由配置的最后
      path: "/:pathMatch(.*)*",
      redirect: "/notfound",
    },
  ],
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `瑞米派 - ${to.meta.title}` : `瑞米派`;
  next();
});

export default router;
